#ifndef PARAMSTUNING_WINDOW_H
#define PARAMSTUNING_WINDOW_H

#include <QDialog>
#include "qnode.hpp"
#include <QMouseEvent>
#include <QTimer>
#include <QDoubleSpinBox>
#include <QSlider>
#include <QMutex>
#include <QReadWriteLock>

typedef enum{
    Curve_Sin,
    Curve_Triangle,
    Curve_Quare
}Curve_Type;

typedef struct{
    Curve_Type curve_type;
    uint32_t freq[3];
    float amp[3];
    float origin[3];
    bool legs_enable[4];
    bool axis_enable[3];
    float Kp[3];
    float Kd[3];
}Curve_Inf;

namespace Ui {
class paramstuning_window;
}

namespace alphadog_monitor {

class paramstuning_window : public QDialog
{
    Q_OBJECT

public:
    explicit paramstuning_window(QWidget *parent = 0, QNode* _qnode = nullptr);
    ~paramstuning_window();

public Q_SLOTS:
    void publishCmd(void);

protected:
    void mousePressEvent(QMouseEvent *event);//鼠标点击
    void mouseMoveEvent(QMouseEvent *event);//鼠标移动事件
    void mouseReleaseEvent(QMouseEvent *event);//鼠标释放事件
    QPoint m_offPos;
private:
    Ui::paramstuning_window *ui;
    QNode* qnode;
    Curve_Inf inf;
    QTimer* timer;
    std::vector<QDoubleSpinBox*> controller_boxes;
    std::vector<QSlider*> controller_sliders;
    sensor_msgs::JointState msg;
    std::vector<sensor_msgs::JointState> msgs;
//    QReadWriteLock rwlocker;
    void initWidget(void);
    void updateCurveInf(Curve_Inf* _curve);
    void calculateCurve(Curve_Inf* _curve, std::vector<sensor_msgs::JointState>& _msgs);
    void saveParams(void);
    void loadParams(void);
};

}

#endif // PARAMSTUNING_WINDOW_H
